package com.example.photograph.controller;

import com.example.photograph.common.core.controller.BaseController;
import com.example.photograph.common.core.domain.AjaxResult;
import com.example.photograph.common.core.page.TableDataInfo;
import com.example.photograph.domain.StatisticsEmploymentPlusVo;
import com.example.photograph.domain.StatisticsEmploymentQuery;
import com.example.photograph.domain.StatisticsEmploymentVo;
import com.example.photograph.domain.SysEmployment;
import com.example.photograph.domain.SysMajor;
import com.example.photograph.domain.SysSchool;
import com.example.photograph.domain.SysUser;

import com.example.photograph.service.ISysEmploymentService;
import com.example.photograph.service.ISysMajorService;
import com.example.photograph.service.ISysSchoolService;
import com.example.photograph.service.ISysUserService;
import com.example.photograph.shiro.service.SysRegisterService;
import com.example.photograph.utils.Random;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 功能描述：
 *
 * @Author： phm
 * @Date： 2021-05-01 22:53
 */
@Controller
@RequestMapping("/photograph/statistics")
public class SysStatisticsEmploymentController extends BaseController {

    private String prefix = "photograph/statistics";

    @Autowired
    private ISysEmploymentService sysEmploymentMapper;

    @RequiresPermissions("photograph:statisticsEmployment:view")
    @GetMapping()
    public String statisticsEmployment()
    {
        return prefix + "/statisticsEmployment";
    }

    /**
     * 查询学院管理列表
     */
    @RequiresPermissions("photograph:statisticsEmployment:list")
    @PostMapping("/statisticsEmployment")
    @ResponseBody
    public AjaxResult statisticsEmployment(StatisticsEmploymentQuery statisticsEmploymentQuery)
    {
//        this.createEmployment();
        StatisticsEmploymentPlusVo statisticsEmploymentVos = sysEmploymentMapper.statisticsEmployment(statisticsEmploymentQuery);


        return new AjaxResult(AjaxResult.Type.SUCCESS,"成功",statisticsEmploymentVos);
    }

    @Autowired
    ISysSchoolService sysSchoolService;
    @Autowired
    ISysMajorService sysMajorService;
    @Autowired
    ISysUserService sysUserService;
    @Autowired
    SysRegisterService statisticsEmploymentVos;
    /**
     * 查询学院管理列表
     */
    @GetMapping("/createStudent")
    @ResponseBody
    public AjaxResult createStudent()
    {
        int index =0;
        for (int i = 0; i <100 ; i++) {

            List<SysSchool> sysSchools = sysSchoolService.selectSysSchoolList(new SysSchool());
            for (SysSchool sysSchool : sysSchools) {
                SysMajor sysMajor1 = new SysMajor();
                sysMajor1.setSchoolId(sysSchool.getId());
                List<SysMajor> sysMajors = sysMajorService.selectSysMajorList(sysMajor1);
                for (SysMajor sysMajor : sysMajors) {

                        index++;
                        SysUser sysUser = new SysUser();
                        sysUser.setRoleId(2L);
                        sysUser.setUserName("小白"+index);
                        sysUser.setLoginName("xiaobai"+index);
                        sysUser.setPassword("xiaobai"+index);
                        sysUser.setMajorId(String.valueOf(sysMajor.getId()));
                        sysUser.setSchoolId(String.valueOf(sysSchool.getId()));
                        statisticsEmploymentVos.register(sysUser);

                }

            }


        }

        return new AjaxResult(AjaxResult.Type.SUCCESS,"成功",statisticsEmploymentVos);
    }


    @Autowired
    ISysEmploymentService sysEmploymentService;

    /**
     * 查询学院管理列表
     */
    @GetMapping("/createEmployment")
    @ResponseBody
    public AjaxResult createEmployment()
    {
        List<SysUser> sysUsers = sysUserService.selectUserList(new SysUser());
        Random random = new Random(sysUsers.size());
        random.reset();
        String [] adderssss = {"北京","山东","福州","厦门","上海","深圳","内蒙古","四川","重庆","合肥"};
        String [] companysss = {"阿里巴巴","字节","百度","新大陆","平多多"};
        for (int i = 0; i <1000 ; i++) {
            int i1 = random.randomInt();
            SysUser sysUser = sysUsers.get(i1);

            SysEmployment sysEmployment = new SysEmployment();
            sysEmployment.setVersions(1L);
            sysEmployment.setUserId(sysUser.getUserId());
            sysEmployment.setAddress(adderssss[i%adderssss.length]);
            sysEmployment.setCompany(companysss[i%companysss.length]);
            sysEmployment.setPosition("普通员工");
            sysEmployment.setSalary("3000");
            sysEmployment.setVersions(1L);

            sysEmploymentService.insertSysEmployment(sysEmployment);
        }

        return new AjaxResult(AjaxResult.Type.SUCCESS,"成功",statisticsEmploymentVos);
    }

}